﻿Imports System.Data.OleDb

Public Class TestPage
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        DrawPieChart()
    End Sub


    Private Sub DrawPieChart()

        Dim wtChart As String = "<script>"
        wtChart += "google.load('visualization', '1.1', { 'packages': ['corechart'] });"

        wtChart += "google.setOnLoadCallback(drawChart);"

        wtChart += "function drawChart() {"
        wtChart += "var data = new google.visualization.DataTable();"
        wtChart += "data.addColumn('string', 'Type_ID');"
        wtChart += "data.addColumn('number', 'NumTypes');"
        wtChart += "data.addRows(["

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("recipeConnectionString").ConnectionString)
        Dim SqlString As String = "SELECT * from STAT_RECIPE_BY_TYPE_VIEW"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        oleDbConn.Open()

        Dim dr As OleDbDataReader = cmd.ExecuteReader

        If dr.HasRows Then
            Do While dr.Read()
                wtChart += "['" + (dr("TYPE_DESC").ToString) + "', " + (dr("NUMTypes").ToString) + "],"
            Loop
        End If

        dr.Close()

        wtChart = wtChart.Substring(0, wtChart.Length - 1)

        wtChart += "]);"
        wtChart += "var options = { 'title': '', 'width': 600, 'height': 350, is3D: true };"
        wtChart += "var chart = new google.visualization.PieChart(document.getElementById('chart_div'));"
        wtChart += "chart.draw(data, options);"

        wtChart += "}"
        wtChart += "</script>"
        Literal1.Text = wtChart

    End Sub

End Class